package com.monster.controller;

import com.monster.entity.Result;
import com.monster.service.OrderSettingService;
import com.monster.utils.poi.POIUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
public class OrderSettingController {

    @Reference
    OrderSettingService orderSettingService;

    @PostMapping("web/ordersetting/importOrderSettings")
    public Result importOrderSettings(@RequestParam("excelFile") MultipartFile file){
        try {
            //rows行对象
            List<String[]> OrderSettingList = POIUtils.readExcel(file);
            orderSettingService.importOrderSettings(OrderSettingList);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new Result(true);
    }

    @GetMapping("web/ordersetting/findSettingData/{year}/{month}")
    public Result findSettingData(@PathVariable("year") int year,@PathVariable("month") int month){
        Result result = new Result(orderSettingService.findSettingData(year, month));
        return result;
    }

    @PutMapping("web/ordersetting/updateNumberByOrderdate/{number}/{orderdate}")
    public Result updateNumberByOrderdate(@PathVariable("number") int number,@PathVariable("orderdate") String orderdate){
        return  new Result(orderSettingService.updateNumberByOrderdate(number,orderdate));
    }
}
